package day02;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.util.Collector;
import untils.ClickEvent;
import untils.ClickSource;
import untils.IntSource;

import java.util.stream.Stream;

public class Example6 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .addSource(new ClickSource())
                .keyBy(r -> 1)
                .process(new KeyedProcessFunction<Integer, ClickEvent, ClickEvent>() {
                    @Override
                    public void processElement(ClickEvent value, Context ctx, Collector<ClickEvent> out) throws Exception {
                        if(value.username.equalsIgnoreCase("Money")){
                            out.collect(value);
                            out.collect(value);
                        } else if (value.username.equals("Doller")){
                            out.collect(value);
                        }
                    }
                })
                .print();

        env.execute();
    }
}
